package jsyf.oa.web.report;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.report.EmailReportFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2018/1/9 0009.
 */
@Api(value = "报表接口", description = "报表接口")
@Controller
@RequestMapping("/report")
public class EmailReportController {
    @Resource
    private EmailReportFacade emailReportFacade;


    @RequestMapping(value = "/emailReport.json", method = RequestMethod.POST)
    public void getUserByUserId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String reportDate = jsonParams.getString("reportDate");
        String readerName = jsonParams.getString("readerName");
        List<JSONObject> resultList = this.emailReportFacade.emailReport(reportDate, readerName);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @RequestMapping(value = "/emailReportForDay.json", method = RequestMethod.POST)
    public void emailReportForDay(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> resultList = this.emailReportFacade.emailReportForDay(jsonData);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }
}
